/*
 * 	Flan.Zeng 2011-2016	http://git.oschina.net/signup?inviter=flan
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.flan.stock.view;

import java.util.List;

import com.flan.stock.bean.FsCoordinateSystem;
import com.flan.stock.bean.Stock;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;

/**
 * 绘制分时走势线的视图
 * @author flan
 * @date   2015年11月4日
 */
public class StockFSView extends View{
	
	private List<Stock> stockList;
	private Paint paint;
	private FsCoordinateSystem fsCoordinateSystem;
	private int viewWidth,viewHeight;

	public StockFSView(Context context) {
		super(context,null);
	}

	public StockFSView(Context context, AttributeSet attrs) {
		super(context, attrs);
		
		//获取视图的尺寸
		ViewTreeObserver vto = this.getViewTreeObserver();
		vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
			
			@Override
			public void onGlobalLayout() {
				//监听器注册后每次视图尺寸发生变化时都会调用，如果只想获取一次视图的尺寸，则需要在获取到视图尺寸后注销掉该监听器
				StockFSView.this.getViewTreeObserver().removeGlobalOnLayoutListener(this);
				viewWidth = StockFSView.this.getWidth();
				viewHeight = StockFSView.this.getHeight();
				fsCoordinateSystem = new FsCoordinateSystem(viewWidth,viewHeight);
			}
		});
		paint = new Paint();
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		
		if(fsCoordinateSystem != null){
			fsCoordinateSystem.drawCoordinateSystem(canvas,paint);
		}
		
	}
	
	
	public void setStockList(List<Stock> stockList) {
		this.stockList = stockList;
	}
	
}
